import { Injectable } from '@nestjs/common';
import * as Minio from 'minio';
const MINIO_CLIENT = new Minio.Client({
  endPoint: 'localhost',
  port: 9000,
  useSSL: false,
  accessKey: 'WESw5gO73pikjp18FMI9',
  secretKey: 'I4BAonf8SZGdDw1y5UwGPsq3A8t0edx7qTi7NO3v',
});
@Injectable()
export class FileService {
  async upload() {
    try {
      await MINIO_CLIENT.fPutObject(
        'electron',
        'results.json',
        './results.json',
      );
      return 'http://localhost:9000/electron/results.json';
    } catch (e) {
      console.log(e);
      return '上传失败';
    }
  }

  presignedUrl(name) {
    return MINIO_CLIENT.presignedPutObject('electron', name, 3600);
  }
}
